package cn.studyjava.verify.code12306.util;

import java.util.HashMap;
import java.util.Map;

import cn.studyjava.verify.code12306.common.Const;
import cn.studyjava.verify.code12306.common.enums.StyleEnum;
import cn.studyjava.verify.code12306.model.Space;

/**
 * 计算位置工具
 * @author zsljava
 *
 */
public class SpaceUtil {
	
	/**
	 * 
	 * @Title:SpaceUtil
	 * @Description:防止实例化对象
	 */
	private SpaceUtil(){}
	
	private static Map<String, Space> map = new HashMap<>();

	public static Space getSpace(Integer space, StyleEnum style){
		String spName = style.getFeatureName() + space;
		Space spa = map.get(spName);
		if(spa != null ){
			return spa;
		}
		Space sp = null; 
		switch (space) {
		case 0:
			sp = new Space((Const.WIDTH * 0 + Const.PADDING * 1),
					(Const.WIDTH * 1 + Const.PADDING * 1 + Const.BODER * 1), (Const.TEXT_HEIGHT + Const.PADDING),
					(Const.TEXT_HEIGHT + Const.PADDING + Const.HEIGHT));
			map.put(spName, sp);
			return sp;
		case 1:
			sp = new Space((Const.WIDTH * 1 + Const.PADDING * 3),
					(Const.WIDTH * 2 + Const.PADDING * 4 + Const.BODER * 2), (Const.TEXT_HEIGHT + Const.PADDING),
					(Const.TEXT_HEIGHT + Const.PADDING + Const.HEIGHT));
			map.put(spName, sp);
			return sp;
		case 2:
			sp =  new Space((Const.WIDTH * 2 + Const.PADDING * 5),
					(Const.WIDTH * 3 + Const.PADDING * 6 + Const.BODER * 3), (Const.TEXT_HEIGHT + Const.PADDING),
					(Const.TEXT_HEIGHT + Const.PADDING + Const.HEIGHT));
			map.put(spName, sp);
			return sp;
		case 3:
			if(style.getFeatureName().equals(StyleEnum.EIGHT.getFeatureName())){
				sp = new Space((Const.WIDTH * 3 + Const.PADDING * 7),
						(Const.WIDTH * 4 + Const.PADDING * 8  + Const.BODER * 4), (Const.TEXT_HEIGHT + Const.PADDING),
						(Const.TEXT_HEIGHT + Const.PADDING + Const.HEIGHT));
				map.put(spName, sp);
				return sp;
			}else if(style.getFeatureName().equals(StyleEnum.SIX.getFeatureName())
					|| style.getFeatureName().equals(StyleEnum.NINE.getFeatureName())){
				sp = new Space((Const.WIDTH * 0 + Const.PADDING * 1),
						(Const.WIDTH * 1 + Const.PADDING * 2 + Const.BODER * 1),
						(Const.TEXT_HEIGHT + Const.HEIGHT + Const.PADDING * 3), (Const.TEXT_HEIGHT
								+ Const.HEIGHT * 2 + Const.PADDING * 3));
				map.put(spName, sp);
				return sp;
			}
			break;
		case 4:
			if(style.getFeatureName().equals(StyleEnum.EIGHT.getFeatureName())){
				sp =  new Space((Const.WIDTH * 0 + Const.PADDING * 1),
						(Const.WIDTH * 1 + Const.PADDING * 2  + Const.BODER * 2),
						(Const.TEXT_HEIGHT + Const.HEIGHT + Const.PADDING * 3), (Const.TEXT_HEIGHT
								+ Const.HEIGHT * 2 + Const.PADDING * 3));
				map.put(spName, sp);
				return sp;
			}else if(style.getFeatureName().equals(StyleEnum.SIX.getFeatureName())
					|| style.getFeatureName().equals(StyleEnum.NINE.getFeatureName())){
				sp =  new Space((Const.WIDTH * 1 + Const.PADDING * 3 + Const.BODER * 2),
						(Const.WIDTH * 2 + Const.PADDING * 4),
						(Const.TEXT_HEIGHT + Const.HEIGHT + Const.PADDING * 3), (Const.TEXT_HEIGHT
								+ Const.HEIGHT * 2 + Const.PADDING * 3));
				map.put(spName, sp);
				return sp;
			}
			break;
		case 5:
			if(style.getFeatureName().equals(StyleEnum.EIGHT.getFeatureName())){
				sp =  new Space((Const.WIDTH * 1 + Const.PADDING * 3),
						(Const.WIDTH * 2 + Const.PADDING * 4 + Const.BODER * 2),
						(Const.TEXT_HEIGHT + Const.HEIGHT + Const.PADDING * 3), (Const.TEXT_HEIGHT
								+ Const.HEIGHT * 2 + Const.PADDING * 3));
				map.put(spName, sp);
				return sp;
			}else if(style.getFeatureName().equals(StyleEnum.SIX.getFeatureName())
					|| style.getFeatureName().equals(StyleEnum.NINE.getFeatureName())){
				sp = new Space((Const.WIDTH * 2 + Const.PADDING * 5),
						(Const.WIDTH * 3 + Const.PADDING * 6 + Const.BODER * 3),
						(Const.TEXT_HEIGHT + Const.HEIGHT + Const.PADDING * 3), (Const.TEXT_HEIGHT
								+ Const.HEIGHT * 2 + Const.PADDING * 3));
				map.put(spName, sp);
				return sp;
			}
			break;
		case 6:
			if(style.getFeatureName().equals(StyleEnum.EIGHT.getFeatureName())){
				sp = new Space((Const.WIDTH * 2 + Const.PADDING * 5),
						(Const.WIDTH * 3 + Const.PADDING * 6 + Const.BODER * 3),
						(Const.TEXT_HEIGHT + Const.HEIGHT + Const.PADDING * 3), (Const.TEXT_HEIGHT
								+ Const.HEIGHT * 2 + Const.PADDING * 3));
				map.put(spName, sp);
				return sp;
			}else if(style.getFeatureName().equals(StyleEnum.NINE.getFeatureName())){
				sp = new Space((Const.WIDTH * 0 + Const.PADDING * 1),
						(Const.WIDTH * 1 + Const.PADDING * 2 + Const.BODER * 1),
						(Const.TEXT_HEIGHT + Const.HEIGHT * 2 + Const.PADDING * 3), (Const.TEXT_HEIGHT
								+ Const.HEIGHT * 3 + Const.PADDING * 3));
				map.put(spName, sp);
				return sp;
			}
			break;
		case 7:
			if(style.getFeatureName().equals(StyleEnum.EIGHT.getFeatureName())){
				sp = new Space((Const.WIDTH * 3 + Const.PADDING * 7),
						(Const.WIDTH * 4 + Const.PADDING * 8 + Const.BODER * 4),
						(Const.TEXT_HEIGHT + Const.HEIGHT + Const.PADDING * 3), (Const.TEXT_HEIGHT
								+ Const.HEIGHT * 2 + Const.PADDING * 3));
				map.put(spName, sp);
				return sp;
			}else if(style.getFeatureName().equals(StyleEnum.NINE.getFeatureName())){
				sp = new Space((Const.WIDTH * 1 + Const.PADDING * 3),
						(Const.WIDTH * 2 + Const.PADDING * 4 + Const.BODER * 2),
						(Const.TEXT_HEIGHT + Const.HEIGHT * 2 + Const.PADDING * 3), (Const.TEXT_HEIGHT
								+ Const.HEIGHT * 3 + Const.PADDING * 3));
				map.put(spName, sp);
				return sp;
			}
			break;
		case 8:
			if(style.getFeatureName().equals(StyleEnum.NINE.getFeatureName())){
				sp = new Space((Const.WIDTH * 2 + Const.PADDING * 5),
						(Const.WIDTH * 3 + Const.PADDING * 6 + Const.BODER * 3),
						(Const.TEXT_HEIGHT + Const.HEIGHT * 2 + Const.PADDING * 3), (Const.TEXT_HEIGHT
								+ Const.HEIGHT * 3 + Const.PADDING * 3));
				map.put(spName, sp);
				return sp;
			}
			break;
		default:
			break;
		}
		return null;
	}
}
